package logic

import (
	"context"
	"errors"
	"month2/C/rpc_C/model/mysql"
	"month2/C/rpc_C/model/redis"

	"month2/C/rpc_C/internal/svc"
	"month2/C/rpc_C/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginLogic) Login(in *order.LoginRequest) (*order.LoginResponse, error) {
	get := redis.Client.Get(context.Background(), "smsLogin")
	if get.Val() != in.Code {
		logx.Error("验证码错误")
		return nil, errors.New("验证码错误")
	}
	var user mysql.User1
	mysql.DB.Find(&user)
	return &order.LoginResponse{Id: int64(user.ID)}, nil
}
